package com.doumi.biz.qadev.api.testcase.commonfilter;

import com.doumi.biz.qadev.api.methods.OperationRedis;
import com.doumi.biz.qadev.api.testcase.RequestTemplate;
import io.restassured.path.json.JsonPath;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by YDZ on 2019/11/20.
 */
public class CommonFilterJobDateType {
    private RequestTemplate requestTemplate = new RequestTemplate();
    private OperationRedis operationRedis = new OperationRedis();
    private static List<String> cuIds = new ArrayList<>();

    //redis初始化数据
    @BeforeClass(description = "初始化redis数据,一个用户信息为在家可做用户，另一个部位在家可做用户")
    public  void operationData(){
        String filenanme = "src/source/redisfile/filter-jobDateType.csv";
        String mothodname = "jobDateType";
        cuIds = operationRedis.readCsvoperationRedis(filenanme,mothodname,1);
    }
    @Test(description = "测试2个用户，其中220638177为在家可做用户，220638178非在家可做用户，预期返回数据中的值为260638178，code状态码是否为0，msg信息是否为success")
    public void checkOnlyCuseridIsJobDateTypeNormal(){
        StringBuffer sb = new StringBuffer("[");
        for (int i = 0; i <cuIds.size()-1;  i++) {
            sb.append(cuIds.get(i).trim()).append(",");
        }
        sb.append(cuIds.get(cuIds.size()-1).trim());
        sb.append("]");
        HashMap hashMap = new HashMap();
        hashMap.put("cuIds",sb.toString());
        hashMap.put("businessType","1");
        JsonPath jsonPath =requestTemplate.postCommonFilter(hashMap);
        List resurlt = jsonPath.getList("data");
        String msg = jsonPath.getString("msg");
        Assert.assertEquals(resurlt.size(),1);
        Assert.assertEquals(String.valueOf(resurlt.get(0)),String.valueOf(220638178));
        Assert.assertEquals(msg,"success");
    }
    @Test(description = "请求参数中的用户为在家可做用户，则直接过滤掉该用户，接口返回的data长度为0，返回的code码为0")
    public void checkOnlyCuseridIsJobDateTypeUNnormal(){
        HashMap hashMap = new HashMap();
        hashMap.put("cuIds","220638177");
        hashMap.put("businessType","1");
        JsonPath jsonPath =requestTemplate.postCommonFilter(hashMap);
        List resurlt = jsonPath.getList("data");
        String code = jsonPath.getString("code");
        Assert.assertEquals(resurlt.size(),0);
        Assert.assertEquals(code,"200");
    }

    //删除数据
    @AfterClass(description = "删除出入掉的数据，避免影响其他测试")
    public void removeData(){
        operationRedis.removeRedis(cuIds);
    }
}
